package com.team.recruitment_management_system.controller;


import com.team.recruitment_management_system.pojo.entity.Tag;
import com.team.recruitment_management_system.service.TagService;

import com.team.recruitment_management_system.util.JwtHelper;
import com.team.recruitment_management_system.util.result.Result;
import com.team.recruitment_management_system.util.result.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * time 2024.3.27
 * author xxxty
 */
@RestController
@RequestMapping("/tag")
@io.swagger.v3.oas.annotations.tags.Tag(name = "标签模块")
public class TagController {
    @Autowired
    TagService tagService;
    @Autowired
    JwtHelper jwtHelper;
    @PutMapping("/update")
    @Operation(summary = "修改标签", security = @SecurityRequirement(name = "Authorization"))
    public Result update(@RequestBody Tag tag){
        boolean i = tagService.updateById(tag);
        return i ?Result.ok(null,"修改成功"):Result.build(null, ResultCodeEnum.ILLEGAL_OPERATION);
    }

    @GetMapping("/getAll")
    @Operation(summary = "查询全部标签")
    public Result GetAll(){
        return Result.ok(tagService.getAll());
    }

    @GetMapping("/getByname/{name}")
    @Operation(summary = "查询标签")
    public Result GetByname(@PathVariable String name){
        return Result.build(tagService.getByName(name),"");
    }

    @PostMapping("/add")
    @Operation(summary = "新增标签")
    public Result add(@RequestBody Tag tag){
        return Result.ok(null, tagService.add(tag));
    }
}
